function save() {
	$("#uid").val($("#useridoflogin").val());
	$("#usertype").val($("#usertypeoflogin").val());
	var typeId = $('#usertypeoflogin').val();
	var id = $('#useridoflogin').val();
	$.ajax({
		//url:"http://127.0.0.1/res/need/addmanage",
		url : Server +"/res/need/addmanage",
		type : "post",
		data : $('#saveneedmanageForm').serialize(),
		success : function(data) {
			alert("添加成功");
	        $(location).attr('href', "new_file44");
		},
		error : function(msg) {
			alert("添加失败");
		}
	});
}

	$(function() {
		var i = 1;
		$('#loop').click(function(trade) {
			var type = "";
			trade = $('#5').val();
			switch(trade){
				case "1":
					type = "海水淡化"
					break;
				case "2":
					type = "海洋船舶"
					break;
				case "3":
					type = "其它技术"
					break;
				case "10":
					type = "海水养殖"
					break;
				case "11":
					type = "海底矿产利用"
					break;
				case "12":
					type = "海洋能源利用"
					break;
				case "13":
					type = "海洋渔业资源"
					break;
				case "14":
					type = "保护与监测"
					break;
				case "15":
					type = "渔业捕捞"
					break;
				default:
					type = "";
					break;
			}
			var str ="";
			//$("#7").val(trade);
			if (i < 10) {
				str += '<div class="item" id="inputclass"><input type="text" name="tradeName"  value="'+ type +'" /><input id="usertype" name="tradeName'+ i +'" value="'+ trade +'" type="text" style="display:none" /><img onclick="clickimg(this)" id="remove" src="images/publishDemandReduce.png" /></div>';
				$('#main').append(str);
				i++;
			} else {
				alert("最多加9个");
			}
		});
	});

function clickimg(m){
	
	m.parentElement.parentElement.removeChild(m.parentElement)
}
function get(){
	var typeId = $('#usertypeoflogin').val();
	var id = $('#useridoflogin').val();
	$.ajax({
		url:"http://127.0.0.1/res/need/get",
		type : "POST",
		dataType : "JSON",
		data : {
			"offset" : 0,
			"limit" : 10,
			"typeId" : typeId ,
			"id" : id ,
		},
		success:function(data){
			//alert(id +   'sss'  +typeId);
			var m = data.rows;
			$("#0").val(m[0].contacts);
			$("#1").val(m[0].phone);
			$("#2").val(m[0].email);
			$("#3").val(m[0].unit);
			$("#4").val(m[0].address);
		}
	})
}

function load() {
	var typeId = $('#usertypeoflogin').val();
	var id = $('#useridoflogin').val();
	//alert(id + usertype);
	$.ajax({
		//url:"http://127.0.0.1/res/need/get",
		url : Server +"/res/need/user",
		data : {
			"typeId" : typeId,
			"id" : id,
		},
		type : "POST",
		dataType:"JSON",
		success : function(data) {
			var scz = data[0];
			if(typeId == 1){//个人
				$("#0").val(scz.puRealname);
				$("#1").val(scz.puPhone);
				$("#2").val(scz.puEmail);
				$("#3").val(scz.puUnit);
				$("#4").val(scz.puAddress);
			}else if(typeId == 2){//企业
				$("#0").val(scz.uuUnitName);
				$("#1").val(scz.uuPhone);
				$("#2").val(scz.uuEmail);
				$("#3").val(scz.uuContacts);
				$("#4").val(scz.uuUnitAddress);
			}
			/*var m = data.rows;
			$("#0").val(m[0].contacts);
			$("#1").val(m[0].phone);
			$("#2").val(m[0].email);
			$("#3").val(m[0].unit);
			$("#4").val(m[0].address);*/
		}
	})
}

function GetQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if(r != null) return unescape(r[2]);
	return null;
}